$(function(){
  gethistory()
  //进入页面请求历史记录
  function gethistory(){
  axios({
    url:'getHistory',
    method:'GET',
    params:{
      uid:nowuser.uid
    }
  }).then(function(res){
    $('.history').empty()
    if(res.data.data.length==0){
      $('.history').append(`<div class="nodata">
          暂无数据
      </div>`)
    }
    $(res.data.data).each(function(index,ele){
        if(ele.detailType!=0){
          if(ele.upTime!='已完结'){
            ele.upTime='更新中'
          }
        $('.history').append(`<div class="historybox">
        <span class="time">${ele.historyTime}</span>
        <a href="./animedetail.html?vid=${ele.videoId}" target="_blank">
        <img src="${ele.videoImg}" alt="">
        </a>
        <p>${ele.historyTitle}</p>
        <div class="historymsg">
          <span>${ele.upTime}</span>
          <span></span>
        </div>
        <img data-id="${ele.historyId}" class="delbtn pointer" src="./img/upload/删除.svg" alt="">
      </div>`)
      
      }else{
        $('.history').append(`<div class="historybox">
          <span class="time">${ele.historyTime}</span>
          <a href="./uservideodetail.html?vid=${ele.videoId}" target="_blank">
          <img src="${ele.videoImg}" alt="">
           </a>
          <p>${ele.historyTitle}</p>
          <div class="historymsg">
            <span>${ele.username}</span>
            <span></span>
          </div>
         
          <img data-id="${ele.historyId}" class="delbtn pointer" src="./img/upload/删除.svg" alt="">
        </div>`)
      }
    })
  })
}

  //删除历史记录
  $('.history').on('click','.delbtn',function(){
    if(confirm('确定要删除这条历史记录吗')){
      console.log($(this).attr('data-id'))
      axios({
        url:'deleteHistory',
        method:'get',
        params:{
          hid:$(this).attr('data-id')
        }
      }).then(res=>{
        $('.history').empty()
        gethistory()
        resSuccess('删除成功')
      })

    }
  })
  //清空历史记录
  $('.topright span').click(function(){
    if(confirm('确定要删除所有历史记录吗')){
      axios({
        url:'deleteall',
        method:'get',
        params:{
          uid:nowuser.uid
        }
      })
      resSuccess('删除成功')
      location.reload()
    }
  })
})
